////////////////////////////////////////////////////////////////////////////////////////////////////
/// Copyright (c) 2009 - 2010 RacoonStudios
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy of this
/// software and associated documentation files (the "Software"), to deal in the Software
/// without restriction, including without limitation the rights to use, copy, modify, merge,
/// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
/// to whom the Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all copies or
/// substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
/// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
/// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
/// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
/// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
/// DEALINGS IN THE SOFTWARE.
////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once
#ifndef singleton_h__
#define singleton_h__

#include "core\config.h"

////////////////////////////////////////////////////////////////////////////////////////////////////
///
///	How to use this Singleton-Class:
///
///  Place the RE_DeclareSingleton(type) within the declaration of the class.
///	The type is the class itself.
///
///	Place the RE_ImplementSingleton(type) within the implementation of the class.
///	The type is the class itself.
///
///	Place the RE_ConstructSingleton() within your class startup procedure.
///	This should normally be the constructor.
///
///	Place the RE_DestructSingleton() within your class shutdown procedure.
///	For normal this should be the destructor.
///
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \def	RE_DeclareSingleton(type) public: static type * Singleton
///
/// \brief	declare singleton. 
///
/// \remarks	khaos, 03.12.2009. 
///
/// \param	[in]	type	The type. 
////////////////////////////////////////////////////////////////////////////////////////////////////
#define RE_DeclareSingleton(type) \
	public: \
	static type * Singleton; \
	bool HasInstance() { return (0 != Singleton); } \
	static type * GetInstance() { return Singleton; } \
	private:

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \def	RE_ImplementSingleton(type) type::Singleton = NULL
///
/// \brief	implement singleton. 
///
/// \remarks	khaos, 03.12.2009. 
///
/// \param	[in]	type	The type. 
////////////////////////////////////////////////////////////////////////////////////////////////////
#define RE_ImplementSingleton(type) \
	type * type::Singleton = 0; 

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \def	RE_CreateSingleton() Singleton = this
///
/// \brief	create singleton. 
///
/// \remarks	khaos, 03.12.2009. 
////////////////////////////////////////////////////////////////////////////////////////////////////
#define RE_CreateSingleton() \
	Singleton = this;

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \def	RE_DestroySingleton() Singleton = NULL
///
/// \brief	detroy singleton. 
///
/// \remarks	khaos, 03.12.2009. 
////////////////////////////////////////////////////////////////////////////////////////////////////
#define RE_DestroySingleton() \
	Singleton = 0;

#endif // singleton_h__